from django.shortcuts import render_to_response
from django.core.paginator import ObjectPaginator,InvalidPage
from django.template import RequestContext

def show_page(request,page,objects,template,onPage=10):
	page = int(page)
	c = RequestContext(request)
	p = ObjectPaginator(objects,onPage)

	try:
		c['objects'] = p.get_page(page)
	except InvalidPage:
		pass
	
	c['page'] = page
	if p.has_previous_page(page):
		c['prev_page'] = str(page-1) #str, because we don't want to treat 0 as false
	if p.has_next_page(page):
		c['next_page'] = str(page+1) 
	c['page_count'] = str(p.pages)

	return render_to_response(template,c)
